package org.example.spring.simple.framework.aop.intercept;

import org.example.spring.simple.framework.aop.aspect.ZAbstractAspectJAdvice;
import org.example.spring.simple.framework.aop.aspect.ZAdvice;

import java.lang.reflect.Method;

public class ZAfterThrowingAdviceInterceptor extends ZAbstractAspectJAdvice implements ZAdvice, ZMethodInterceptor {
    private String throwingName;
    private ZMethodInvocation invocation;

    public ZAfterThrowingAdviceInterceptor(Method method, Object target) {
        super(method, target);
    }

    public void setThrowingName(String name) {
        this.throwingName = name;
    }

    @Override
    public Object invoke(ZMethodInvocation invocation) throws Throwable {
        try {
            return invocation.proceed();
        } catch (Throwable e) {
            invokeAdviceMethod(invocation, null, e.getCause());
            throw e;
        }
    }
}
